package com.codejiwei.core.rdd

import org.apache.spark.rdd.RDD
import org.apache.spark.{SparkConf, SparkContext}

object Spark_RDD_Create_File {
  def main(args: Array[String]): Unit = {
    val conf = new SparkConf().setMaster("local[2]").setAppName("RDDCreateFile")
    val sc = new SparkContext(conf)

    val lines: RDD[String] = sc.textFile("spark-core/src/main/resources/word.txt")
    val words: RDD[String] = lines.flatMap(_.split(" "))
    val wordOne: RDD[(String, Int)] = words.map((_, 1))
    val wordSum: RDD[(String, Int)] = wordOne.reduceByKey(_ + _)

    wordSum.collect().foreach(println)

    sc.stop()
  }
}
